/**
 * @file objloaderprivate.h
 * @brief ObjLoaderPrivate struct definition
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk) sir.vestnik@gmail.com
 * @date 9 Jul 2010
 */
#ifndef OBJLOADERPRIVATE_H
#define OBJLOADERPRIVATE_H

#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QMap>

struct Vertex
{
    double x;
    double y;
    double z;
    double w;
};

struct VertexNormal
{
    double i;
    double j;
    double k;
};

struct TextureCoord
{
    double u;
    double v;
    double w;
};

/**
 * References to vertex, normal and texture vertex. All indexes starts from
 * 1 see *.obj format specs here: http://local.wasp.uwa.edu.au/~pbourke/dataformats/obj/
 * for more details. 0 value means that this attribute is not specified.
 */
struct VertexRef
{
    VertexRef(int v=0, int vt=0, int vn=0):vertex(v),normal(vn),textureCoord(vt) {}

    /// Vertex reference. This value should never be 0.
    int vertex;
    int normal;
    int textureCoord;
};

struct GeometryObject
{
    enum Type {Points,Lines,Face};

    Type type;
    QList<VertexRef> vertexRefs;
};

struct ObjLoaderPrivate
{
    ObjLoaderPrivate() {clear();}

    QString basePath;
    QString error;
    int errorLine;
    int currentSmoothingGroup;
    QString currentMaterial;

    QList<Vertex> vertexes;
    QList<VertexNormal> normals;
    QList<TextureCoord> textureCoords;
    QMap<int, QMap<QString, QList<GeometryObject> > > geometryObjects;

    void clear();

    bool loadDefinition(const QString &definition);

    bool loadVertex(const QStringList &tokens);
    bool loadNormal(const QStringList &tokens);
    bool loadTextureCoord(const QStringList &tokens);
    bool loadSmoothingGroup(const QStringList &tokens);
    bool loadUseMtl(const QStringList &tokens);
    bool loadGeomObject(const QStringList &tokens);
};


#endif
